# 练习家具

class HouseItem:
    """
    家具类
    """

    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return "[%s] 占地 %.2f " % (self.name, self.area)


class House:
    """
    家类
    """

    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area

        # 剩余面积
        self.free_area = area

        # 家具名称列表
        self.item_list = []

    def __str__(self):
        return ("户型：%s, 总面积：%.2f 剩余[%.2f], 家具：%s"
                % (self.house_type, self.area, self.free_area, self.item_list))

    # 添加家具
    def add_item(self, item):
        # 判断面积
        if item.area > self.free_area:
            print("%s 家具面积太大啦" % item.name)
            return

        # 添加到家具列表
        self.item_list.append(item.name)

        # 计算剩余面积
        self.free_area -= item.area

        pass


# 创建家具
bed = HouseItem("床", 400)
chest = HouseItem("衣柜", 2)
table = HouseItem("餐桌", 1.5)

print(bed)
print(chest)
print(table)

# 创建房子
house = House("两室一厅", 60.00)
house.add_item(bed)
house.add_item(chest)
house.add_item(table)

print(house)
